package http

import (
	"ce-cloud-service/internal/services/gate/hall/controller"
	"ce-cloud-service/pkg/http_middleware"
	"ce-cloud/pkg/log"
	"github.com/gin-gonic/gin"
	swaggerFiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"
	"net/http"
)

func router(api *gin.Engine) {
	api.Use(func(c *gin.Context) {
		c.Header("Accept-Language", "zh-CN,zh")
		c.Header("Accept-Encoding", "gzip,q=1,compress,deflate")
		c.Header("Access-Control-Allow-Origin", "*")
		c.Header("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS,PATCH,HEAD")
		c.Header("Access-Control-Allow-Headers", "*")
		c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Cache-Control, Content-Language, Content-Type")
		c.Header("Access-Control-Allow-Credentials", "true")
		if c.Request.Method == "OPTIONS" {
			c.Status(http.StatusOK)
			log.Warn("OPTION")
		} else {
			c.Next()
		}
	})
	api.Use(func(c *gin.Context) {
		http_middleware.Interceptor{}.Check(c)
	})
	api.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
	user := api.Group("/user")
	user.POST("/register", controller.UserRegister)
	user.POST("/login", controller.UserLogin)
	test := api.Group("/test")
	test.GET("/parseSign", controller.ParseSign)
	test.PATCH("/", controller.TestPatch)
	test.GET("/", controller.TestGet)
	test.DELETE("/", controller.TestDelete)
}
